package com.zwl.module_home

import android.Manifest
import android.util.Log
import android.widget.Toast
import androidx.activity.viewModels
import com.alibaba.android.arouter.launcher.ARouter
import com.permissionx.guolindev.PermissionX
import com.zwl.lib_base.base.BaseActivity
import com.zwl.lib_base.base.HomeApiService
import com.zwl.lib_common.com.zwl.common.constant.RouteUrl
import com.zwl.module_home.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding,MainViewModel>() {
    private val TAG = "MainActivity"

    @Inject
    lateinit var mApi: HomeApiService

    override val mViewModel by viewModels<MainViewModel>()


    override fun createVB(): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun init() {
        PermissionX.init(this)
            .permissions(Manifest.permission.READ_CONTACTS, Manifest.permission.CAMERA, Manifest.permission.CALL_PHONE)
            .onExplainRequestReason { scope, deniedList ->
                scope.showRequestReasonDialog(deniedList, "即将重新申请的权限是程序必须依赖的权限", "OK", "Cancel")
            }
            .onForwardToSettings { scope, deniedList ->
                scope.showForwardToSettingsDialog(deniedList, "您需要去应用程序设置当中手动开启权限", "OK", "Cancel")
            }
            .request { allGranted, grantedList, deniedList ->
                if (allGranted) {
                    Toast.makeText(this, "所有请求的权限都已通过", Toast.LENGTH_LONG).show()
                } else {
                    Toast.makeText(this, "您拒绝了如下权限: $deniedList", Toast.LENGTH_LONG).show()
                }
            }

        dataBinding.tvTitle.setText("hello android init")
        dataBinding.tvTitle.setOnClickListener {
            ARouter.getInstance().build(RouteUrl.Background.MainActivity2).navigation()
            Log.d(TAG, "init: " + mApi)

        }

    }

    override fun initObserve() {

    }

    override fun initRequestData() {


    }

}